import Vue from "vue";
import VueRouter from "vue-router";
import store from '../vuex/store.js'
Vue.use(VueRouter);

const Index = () => import("../pages/index.vue");
const Xiandu = () => import("../pages/xiandu.vue");
const Xiandu_Children = () => import("../pages/xiandu_children.vue");
const Xiandu_Detail = () => import("../pages/xiandu_detail.vue");
const Search = () => import("../pages/search.vue");
const Recommend = () => import("../pages/recommend.vue");
const Classify = () => import("../pages/classify.vue");

const routes = [{
        path: "/",
        redirect: {
            name: "index"
        },
        meta: {
            keepAlive: false // 需要被缓存
        }
    },
    {
        path: "/index",
        component: Index,
        name: "index",
        meta: {
            keepAlive: true // 需要被缓存
        }
    },
    {
        path: "/xiandu",
        component: Xiandu,
        name: "xiandu",
        meta: {
            keepAlive: true // 需要被缓存
        }
    },
    {
        path: "/xiandu_children/:id",
        component: Xiandu_Children,
        name: "xiandu_children",
        meta: {
            keepAlive: true // 需要缓存
        }
    },
    {
        path: "/xiandu_detail",
        component: Xiandu_Detail,
        name: "xiandu_detail",
        meta: {
            keepAlive: false // 不需要缓存
        }
    },
    {
        path: "/search",
        component: Search,
        name: "Search",
        meta: {
            keepAlive: false // 不需要缓存
        }
    },
    {
        path: "/recommend",
        component: Recommend,
        name: "Recommend",
        meta: {
            keepAlive: true // 需要缓存
        }
    },
    {
        path: "/classify",
        component: Classify,
        name: "Classify",
        meta: {
            keepAlive: true // 需要缓存
        }
    },
    {
        path: "*",
        redirect: {
            name: "index"
        },
        meta: {
            keepAlive: false // 需要被缓存
        }
    }
];

const router = new VueRouter({
    routes,
});

// router.beforeEach((to, from, next) => {
//     store.commit('load/setLoadFlag', true)
//     next()
// })

// router.afterEach(function (to) {
//     store.commit('load/setLoadFlag', false)
// })

export default router;